<?php
if( !defined('IN_INDEX') )
{
	die('This page is hidden.');
}

// --------------------------------------------------------
// The class sql_db contains methods for working 
// with the sql database
// --------------------------------------------------------
class sql_db
{
	var $db_connect_id;
	var $query_result;
	var $row;
	var $rowset = array();
	var $num_queries = 0;
	
	function sql_db($sqlserver, $sqluser, $sqlpassword, $database)
	{
		$this->user = $sqluser;
		$this->password = $sqlpassword;
		$this->server = $sqlserver;
		$this->dbname = $database;
		
		$this->db_connect_id = @mysql_connect($this->server, $this->user, $this->password);
		if($this->db_connect_id)
		{
			if($database != "")
			{
				$this->dbname = $database;
				$dbselect = @mysql_select_db($this->dbname);
				
				if(!$dbselect)
				{
					@mysql_close($this->db_connect_id);
					$this->db_connect_id = $dbselect;
				}
			}
			
			return $this->db_connect_id;
		} 
		else 
		{
			return false;
		}
	}
	
	function sql_query($query)
	{
		unset($this->query_result);
		//mysql_query("SET NAMES 'utf8'",$this->db_connect_id);
		if($query != "")
		{
			$this->num_queries++;
			$this->query_result = @mysql_query($query, $this->db_connect_id);
		}
		if($this->query_result)
		{
			unset($this->row[$this->query_result]);
			unset($this->rowset[$this->query_result]);
			return $this->query_result;
		}
	}
	
	function sql_fetchrow($query_id)
	{
		if(!$query_id)
		{
			$query_id = $this->query_result;
		}
		if($query_id)
		{
			$this->row = @mysql_fetch_array($query_id);
			return $this->row;
		}
		else
		{
			return false;
		}
	}
	
	function sql_affectedrows()
	{
		if($this->db_connect_id)
		{
			$result = @mysql_affected_rows($this->db_connect_id);
			return $result;
		}
		else
		{
			return false;
		}
	}
	
	function sql_close()
	{
		@mysql_close($this->db_connect_id);
	}
}
?>